const { Model } = require('sequelize')
const classSchema = require('./classSchema')
const sequelize = require('../../common/sequelize')


class Class extends Model {

  /**
   * @description 创建一个班级，该函数会往数据库中的class表插入一条数据，如果创建成功将会返回对应的班级信息(包含班级id和班级名等信息)
   * @param {string} classname 
   * @returns 创建的班级信息
   */
  static async createClass(classname) {
    try {
      const res = await this.create({ classname })
      return res.dataValues
    } catch (err) {
      console.log(err);
      return false
    }
  }
}

Class.init(classSchema, {
  sequelize,
  modelName: 'Class',
  tableName: 'classes',
  timestamps: true,
  updatedAt: false
})

module.exports = Class